home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP15 / PRINT2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  1.6 KB  |  64 lines

  1. /*------------------------------------------
  2.    PRINT2.C -- Printing with Abort Function
  3.                (c) Charles Petzold, 1996
  4.   ------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. HDC  GetPrinterDC (void) ;              // in PRINT.C
  9. void PageGDICalls (HDC, int, int) ;
  10.  
  11. HINSTANCE hInst ;
  12. char      szAppName[] = "Print2" ;
  13. char      szCaption[] = "Print Program 2 (Abort Function)" ;
  14.  
  15. BOOL CALLBACK AbortProc (HDC hdcPrn, int iCode)
  16.      {
  17.      MSG msg ;
  18.  
  19.      while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
  20.           {
  21.           TranslateMessage (&msg) ;
  22.           DispatchMessage (&msg) ;
  23.           }
  24.      return TRUE ;
  25.      }
  26.  
  27. BOOL PrintMyPage (HWND hwnd)
  28.      {
  29.      static DOCINFO di     = { sizeof (DOCINFO), "Print2: Printing", NULL } ;
  30.      BOOL           bError = FALSE ;
  31.      HDC            hdcPrn ;
  32.      short          xPage, yPage ;
  33.  
  34.      if (NULL == (hdcPrn = GetPrinterDC ()))
  35.           return TRUE ;
  36.  
  37.      xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
  38.      yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
  39.  
  40.      EnableWindow (hwnd, FALSE) ;
  41.  
  42.      SetAbortProc (hdcPrn, AbortProc) ;
  43.  
  44.      if (StartDoc (hdcPrn, &di) > 0)
  45.           {
  46.           if (StartPage (hdcPrn) > 0)
  47.                {
  48.                PageGDICalls (hdcPrn, xPage, yPage) ;
  49.  
  50.                if (EndPage (hdcPrn) > 0)
  51.                     bError = TRUE ;
  52.                }
  53.           }
  54.      else
  55.           bError = TRUE ;
  56.  
  57.      if (!bError)
  58.           EndDoc (hdcPrn) ;
  59.  
  60.      EnableWindow (hwnd, TRUE) ;
  61.      DeleteDC (hdcPrn) ;
  62.      return bError ;
  63.      }
  64.